package listbyorder.access101_200.test167;

import java.util.HashMap;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/6/14 12:28
 */
public class Solution1 {

    // 两数之和
    public int[] twoSum(int[] numbers, int target) {
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < numbers.length; i++) {
            int num = target - numbers[i];
            if (map.containsKey(num)) {
                return new int[]{map.get(num) + 1, i + 1};
            }
            map.put(numbers[i], i);
        }
        throw new RuntimeException("没有找到想要的结果");
    }
}
